package com.un.ebs.sys.controller;


import com.un.ebs.core.util.WebResult;
import com.un.ebs.core.util.WebUtils;
import com.un.ebs.sys.domain.Ent;
import com.un.ebs.sys.domain.EntLinkman;
import com.un.ebs.sys.dto.EntAddDto;
import com.un.ebs.sys.dto.EntLinkmanDto;
import com.un.ebs.sys.dto.EntUpdateDto;
import com.un.ebs.sys.service.EntService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;


/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author liubo
 * @since 2019-09-15
 */
@RestController
@RequestMapping("/ent")
@Api(value = "sys-ent", description = "企业")
public class EntController {

    @Autowired
    private EntService service;

    @PostMapping("add")
    @ApiOperation(value = "add", notes = "添加")
    public WebResult save(@RequestBody EntAddDto req) {
        service.add(req);
        return WebUtils.success();
    }

    @PostMapping("update")
    @ApiOperation(value = "update", notes = "修改")
    public WebResult update(@RequestBody EntUpdateDto req) {
        service.update(req);
        return WebUtils.success();
    }

    @PostMapping("updateDefaultLinkman/{id}")
    @ApiOperation(value = "updateDefaultLinkman", notes = "修改默认联系人")
    public WebResult updateDefaultLinkman(@PathVariable("id") String id) {
        service.setDefaultLinkman(id);
        return WebUtils.success();
    }

    @PostMapping("updateLinkman")
    @ApiOperation(value = "updateLinkman", notes = "修改联系人")
    public WebResult update(@RequestBody EntLinkmanDto req) {
        service.saveLinkman(req);
        return WebUtils.success();
    }

    @GetMapping("/{id}")
    @ApiOperation(value = "getById", notes = "根据主键获取单个 Ent")
    public WebResult getById(@PathVariable("id") String id) {
        return WebUtils.success(service.queryById(id));
    }

    @GetMapping("list")
    @ApiOperation(value = "list", notes = "")
    public WebResult<List<Ent>> list() {
        return WebUtils.success(
                service.list()
        );
    }

    @PostMapping("delete/{id}")
    @ApiOperation(value = "delete", notes = "根据主键删除单个 Ent")
    public WebResult delete(@PathVariable("id") String id) {
        service.delete(id);
        return WebUtils.success();
    }

    @GetMapping("listLinkman")
    @ApiOperation(value = "listLinkman", notes = "")
    public WebResult<List<EntLinkman>> listLinkman(@RequestParam String entId) {
        return WebUtils.success(service.queryLinkman(entId));
    }

    @PostMapping("deleteLinkman/{id}")
    @ApiOperation(value = "deleteLinkman", notes = "根据主键删除单个联系人")
    public WebResult deleteLinkman(@PathVariable("id") String id) {
        service.deleteLinkman(id);
        return WebUtils.success();
    }

}
